package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.Api.SetmealControllerApi;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.service.SetmealDishService;
import com.itheima.reggie.service.SetmealService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lifeihu
 * @date 2021/11/27
 * @TIME:10:50
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController implements SetmealControllerApi {
    @Autowired
    private SetmealService setmealService;
    @PostMapping
    public R addSetmeal(@RequestBody SetmealDto setmealDto){
        setmealService.addSetmeal(setmealDto);
        return R.success("添加成功");
    }
    @GetMapping("/page")
    public R findByPage(Integer page,Integer pageSize,String name){
        Page<SetmealDto> page1 = setmealService.findByPage(page, pageSize, name);
        return R.success(page1);
    }
    @DeleteMapping
    public R deleteByIds(Long[] ids){
        setmealService.deleteByIds(ids);
        return R.success("删除成功");
    }
    @GetMapping("/{id}")
    public R findById(@PathVariable Long id){
        SetmealDto setmealDto = setmealService.findById(id);
        return R.success(setmealDto);
    }
    @PutMapping
    public R updateSetmeal(@RequestBody SetmealDto setmealDto){
        setmealService.updateSetmeal(setmealDto);
        return R.success("修改成功");
    }
    @PostMapping("/status/{status}")
    public R updateByStatus(@PathVariable Integer status,Long[] ids){
        setmealService.updateByStatus(status,ids);
        return R.success("修改成功");
    }
    @GetMapping("/list")
    public R findByQpage(Setmeal setmeal){
        List<Setmeal> setmealList=setmealService.findByQpage(setmeal);
        return R.success(setmealList);
    }
}
